package com.example.rwq_test.stateMonitor;

import com.example.rwq_test.ThreadPool.MyThreadFactory;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author renweiqiang
 * @Date 2024/4/23 下午7:17
 */
public class Main {

    static ThreadPoolExecutor executorPool = new ThreadPoolExecutor(3, 5, 10,
            TimeUnit.SECONDS, new LinkedBlockingQueue<>(7), new MyThreadFactory() , new ThreadPoolExecutor.AbortPolicy());

    public static void main(String[] args) {
        try {
            CountDownLatch countDownLatch = new CountDownLatch(1);
            executorPool.submit(new StateExpectAndRealValueMonitor(StateMonitorEnum.TASK_FINISH, countDownLatch));
            if (countDownLatch.await(StateMonitorEnum.TASK_FINISH.getMonitorTime(), TimeUnit.MILLISECONDS)) {
                System.out.println("task finish success.");
            } else {
                System.out.println("task finish time out.");
            }
        } catch (Exception e) {

        }
    }
}
